<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Calendar" %><%--
  Created by IntelliJ IDEA.
  User: paul1
  Date: 2018/12/18
  Time: 14:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增部门</title>
</head>
<script type="text/javascript"  src="/static/layuiadmin/layui/layui.all.js"></script>
<script type="text/javascript"   src="/static/layuiadmin/layui/layui.js"></script>
<link href="/static/layuiadmin/layui/css/layui.css" rel="stylesheet">


<body>
<form id="myform" class="layui-form" >
    <div class="layui-form-item">
        <label class="layui-form-label">部门名称</label>
        <div class="layui-input-block">
            <input type="text"  id="dname" name="dname" lay-verify="dname" autocomplete="off" placeholder="请输入部门名称" class="layui-input" style="height: 31px;width: 417px;">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>



</body>


<script>
    layui.use(['form', 'layedit', 'laydate','jquery'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,$=layui.jquery;


        //自定义验证规则
        form.verify({
            dname: function(value){
                if(value==""){
                    return '分类名称不能为空';
                }
            }
        });
        //创建一个编辑器
        layedit.build('LAY_demo_editor');

        //监听提交
        form.on('submit(demo1)', function(data){

            $.ajax({
                type:'post', //请求类型
                url:'/dept/insert',//请求url地址
                data:$('#myform').serialize(),
                cache:false,
                async:true,
                timeout:30000,//超时

                success:function(data){
                  if(data.message>0)
                  {
                      var index=parent.layer.getFrameIndex(window.name);//查询出窗口的索引
                      parent.layer.close(index);//关闭该索引的窗口
                      parent.layer.msg("修改成功");
                  }
                  else{
                      parent.layer.msg("修改失败");
                  }
                },
                error:function(data){
                    console.log("请求失败");
                }
            })

            return false;
        });
    });

</script>


</html>
